package org.tinygroup.cepcore.impl;

import java.util.List;

import org.tinygroup.cepcore.CEPCore;
import org.tinygroup.cepcore.CEPCoreProcessFilter;
import org.tinygroup.cepcore.CEPCoreProcessFilterChain;
import org.tinygroup.cepcore.EventProcessor;
import org.tinygroup.commons.tools.CollectionUtil;
import org.tinygroup.event.Event;

public class CEPCoreProcessFilterChainImpl implements CEPCoreProcessFilterChain {
	List<CEPCoreProcessFilter> filters;

	public CEPCoreProcessFilterChainImpl(List<CEPCoreProcessFilter> filters) {
		if(CollectionUtil.isEmpty(filters)){
			return;
		}
		this.filters = filters;
		for(int i = 0 ; i < filters.size()-1;i++){
			CEPCoreProcessFilter filter = filters.get(i);
			filter.setNext(filters.get(i+1));
		}
	}

	public void process(Event e, CEPCore core, EventProcessor processor) {
		if(CollectionUtil.isEmpty(filters)){
			return;
		}
		filters.get(0).process(e, core, processor);
	}

}
